package com.gpj.sqlbuilder.template;

import com.gpj.sqlbuilder.store.sql.Table;

import java.util.List;

/**
 * @className RootTemplate
 * @description TODO
 * @author GPJ
 * @date 2021/4/16 20:47
 * @version 1.0
 **/
public class RootTemplate extends NormalTemplate {
	public RootTemplate(int start, int tail, String template) {
		super(start, tail, null);
		this.id = "1";
		this.template = new StringBuffer(template);
	}

	public String sql(List<Table> tables){
		variables.put("tables", tables);
		this.build();
		return sql.toString();
	}

	@Override
	protected void doBuild() {
		if (!children.isEmpty()) {
			for(Template child : children){
				child.build();
				sql.append(child.getSql());
			}
		}
	}
}
